﻿@model AddPayAccountModel
@{
    ViewBag.Title = "编辑收款账户";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";

    var viewModel = Model ?? new AddPayAccountModel();
    ADZ_MasterEntities dbcontext = new ADZ_MasterEntities();
    Dictionary<string, string> dc = new Dictionary<string, string>();
}

<form id="S_Form" action="@Url.Action("editpayaccount", "supplier")" method="post" class="definewidth m20" enctype="multipart/form-data">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td colspan="2" style="width:50%">
                <h5>@ViewBag.Title</h5>
                <input type="hidden" value="@viewModel.aDZ_SupplierDetails.supplier_id" name="aDZ_SupplierDetails.supplier_id" id="aDZ_SupplierDetails.supplier_id" />
                <input type="hidden" value="@viewModel.aDZ_SupplierDetails.seq_id" name="aDZ_SupplierDetails.seq_id" id="aDZ_SupplierDetails.seq_id" />
                <input type="hidden" value="@viewModel.aDZ_SupplierDetails.is_del" name="aDZ_SupplierDetails.is_del" id="aDZ_SupplierDetails.is_del" />
                <input type="hidden" value="@viewModel.aDZ_SupplierDetails.audit_status" name="aDZ_SupplierDetails.audit_status" id="aDZ_SupplierDetails.audit_status" />
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">供应商名称 <em>*</em></td>
            <td>
                @Model.supplier_name
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">收款货币</td>
            <td>
                <select id="aDZ_SupplierDetails.currency_type" name="aDZ_SupplierDetails.currency_type">
                    @{
                        dc = new Dictionary<string, string>();
                        {
                            dc = new Dictionary<string, string>();
                            var list1 = YiYiTong.Rocket.Helper.EnumHelper.GetEnumItems(typeof(CurrencyType));
                            foreach (var item in list1)
                            {
                                dc.Add(item.Value.ToString(), item.Description);
                            }
                        }
                    }
                    @HtmlPagerHelper.ShowSelectOpton(dc, Model.aDZ_SupplierDetails.currency_type.ToString());
                </select>&nbsp;
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">是否开票</td>
            <td>
                <input type="radio" name="aDZ_SupplierDetails.is_invoice" style="vertical-align:middle; margin-bottom:6px;" value="1" />开票(含税)
                <input type="radio" name="aDZ_SupplierDetails.is_invoice" style="vertical-align:middle; margin-bottom:6px;" value="0" />不开票(未税)
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">是否对私账户</td>
            <td>
                <input type="radio" name="aDZ_SupplierDetails.bank_acc_type" style="vertical-align:middle; margin-bottom:6px;" value="1" />对公账户
                <input type="radio" name="aDZ_SupplierDetails.bank_acc_type" style="vertical-align:middle; margin-bottom:6px;" value="2" />对私账户
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">收款渠道</td>
            <td>
                <select id="channel" name="aDZ_SupplierDetails.channel">
                    @{
                        dc = new Dictionary<string, string>();
                        {
                            dc = new Dictionary<string, string>();
                            dc.Add("1", "银行转账");
                            dc.Add("2", "支付宝");
                            dc.Add("3", "微信");
                        }
                    }
                    @HtmlPagerHelper.ShowSelectOpton(dc, Model.aDZ_SupplierDetails.channel.ToString());
                </select>&nbsp;
            </td>
        </tr>
        <tr id="trBank1">
            <td width="6%" class="tableleft">收款开户银行</td>
            <td>
                <info style="float:left;">
                    <select id="bank_id" name="aDZ_SupplierDetails.bank_id">
                        @{
                            dc = new Dictionary<string, string>();
                            var bank_list = dbcontext.ADZ_Bank.ToList();
                            foreach (var item in bank_list)
                            {
                                dc.Add(item.bank_id.ToString(), item.bank_name);
                            }
                        }
                        @HtmlPagerHelper.ShowSelectOpton(dc, Model.aDZ_SupplierDetails.bank_id.ToString());
                    </select>&nbsp;
                </info>
                <info style="float:left;">
                    <input type="text" name="aDZ_SupplierDetails.branch_bank_name" style="width:200px;" value="@Model.aDZ_SupplierDetails.branch_bank_name" />
                </info>
            </td>
        </tr>
        <tr id="trBank2">
            <td width="6%" class="tableleft">收款方银行开户名</td>
            <td>
                <input type="text" name="aDZ_SupplierDetails.bank_account_name" style="width:300px;" value="@Model.aDZ_SupplierDetails.bank_account_name" />
            </td>
        </tr>
        <tr id="trBank3">
            <td width="6%" class="tableleft">收款方银行账号</td>
            <td>
                <input type="text" name="aDZ_SupplierDetails.bank_account" style="width:300px;" value="@Model.aDZ_SupplierDetails.bank_account" />
            </td>
        </tr>
        <tr id="trAlipay" style="display:none;">
            <td width="6%" class="tableleft">支付宝账号</td>
            <td>
                <input type="text" name="aDZ_SupplierDetails.alipay_account" style="width:300px;" value="@Model.aDZ_SupplierDetails.alipay_account" />
            </td>
        </tr>
        <tr id="trWechat" style="display:none;">
            <td width="6%" class="tableleft">微信账号</td>
            <td>
                <input type="text" name="aDZ_SupplierDetails.wechat_account" style="width:300px;" value="@Model.aDZ_SupplierDetails.wechat_account" />
            </td>
        </tr>
        <tr>
            <td class="tableleft"></td>
            <td colspan="3">
                <p>
                    <span id="spMsg"></span>
                </p>
                <button type="submit" class="btn btn-primary">保 存</button> &nbsp;&nbsp;
                <button type="button" class="btn btn-success" name="backid" id="backid">返回</button>
            </td>
        </tr>
    </table>
</form>

<script>
    BUI.use('bui/overlay', function (overlay) {
        $(function () {
            showOrHide($('#channel option:selected').val());

            //绑定信息
            switch ('@Model.aDZ_SupplierDetails.is_invoice') {
                case '1':
                    $("input[name='aDZ_SupplierDetails.is_invoice']").get(0).checked = true;
                    break;
                case '0':
                    $("input[name='aDZ_SupplierDetails.is_invoice']").get(1).checked = true;
                    break;
                default:
                    $("input[name='aDZ_SupplierDetails.is_invoice']").get(0).checked = true;
                    break;
            }

            //绑定信息
            switch ('@Model.aDZ_SupplierDetails.bank_acc_type') {
                case '1':
                    $("input[name='aDZ_SupplierDetails.bank_acc_type']").get(0).checked = true;
                    break;
                case '2':
                    $("input[name='aDZ_SupplierDetails.bank_acc_type']").get(1).checked = true;
                    break;
                default:
                    $("input[name='aDZ_SupplierDetails.bank_acc_type']").get(0).checked = true;
                    break;
            }
        });

        $('#channel').on('change', function () {
            //判断是否选取prompt属性，无返回值；
            if ($(this).val()) {
                var selectValue = $(this).find('option:selected').val();
                showOrHide(selectValue);
            }
        });
    });

    function showOrHide(value) {
        if (value == 1) {
            $("#trBank1").show();
            $("#trBank2").show();
            $("#trBank3").show();
            $("#trAlipay").hide();
            $("#trWechat").hide();
        }
        else if (value == 2) {
            $("#trBank1").hide();
            $("#trBank2").hide();
            $("#trBank3").hide();
            $("#trAlipay").show();
            $("#trWechat").hide();

        } else if (value == 3) {
            $("#trBank1").hide();
            $("#trBank2").hide();
            $("#trBank3").hide();
            $("#trAlipay").hide();
            $("#trWechat").show();
        }
    }

    BUI.use('bui/form', function (Form) {
        $(function () {
            var validator = $('form').validate({
                errorLabelContainer: $("#errorContainer"),
                errorElement: "span",
                submitHandler: function (form) {
                    $(form).ajaxSubmit(function (result) {
                        ShowActionResult(result, function () { self.location = document.referrer; });
                    });
                }
            });
        });
    });
</script>